package com.letoken.platform.app.configuration;

import com.letoken.platform.repo.wallet.constant.AppRabbitConstant;
import com.letoken.platform.repo.wallet.constant.WalletRabbitConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @author： txx
 * @date： 2021-08-28 16:43
 */
@Configuration
public class RabbitUserConfiguration {

    // ===========================
    // 交换机

    /**
     * 普通交换机-执行及时任务
     * @return
     */
    @Bean
    TopicExchange normalExchange() {
        return new TopicExchange(AppRabbitConstant.TOPIC_EXCHANGE_USER, true, false);
    }



    /**
     * 延时队列-用户钱包充值确认
     * @return
     */
    @Bean
    public Queue queueRechargeConfirmDelay() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange", AppRabbitConstant.TOPIC_EXCHANGE_USER);
        args.put("x-dead-letter-routing-key", AppRabbitConstant.QUEUE_USER_TEAM_DYNAMIC_REWARD);
        return new Queue(AppRabbitConstant.QUEUE_USER_TEAM_DYNAMIC_REWARD, true, false, false, args);
    }

    @Bean
    Binding bindingRechargeConfirmDelay() {
        return BindingBuilder.bind(this.queueRechargeConfirmDelay()).to(this.normalExchange()).with(AppRabbitConstant.QUEUE_USER_TEAM_DYNAMIC_REWARD);
    }





}
